﻿Type=Activity
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim gUid As String,gPname As String
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Private edtpasswd As EditText
	Private edtphone As EditText
	Private thirdlogin As ThirdLogin
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("laylogin")
	initviews
End Sub
Sub initviews
	comm.aio(Activity)
	'test
	edtphone.Text="15509005964"
	edtpasswd.Text="123456"
	thirdlogin.init("tl",comm.SHARE_APPKEY,comm.getShareSdkCfgList,True)
End Sub
Sub Activity_Resume

End Sub
Sub tl_onCancel(action As Int,Platform As Object)
	comm.TL("tl_onCancel:"&action&" "&Platform)
	comm.T("取消了登录")
End Sub
Sub tl_onError(action As Int,platform As Object,errMsg As String)
	comm.L("tl_onError:"&action&" "&errMsg&" "&platform)
	Msgbox("错误:"&errMsg,"登录出错")
End Sub
Sub tl_onComplete(action As Int,platform As Object,res As Map)
	'comm.TL("tl_onComplete:"&action&" "&res&" "&platform)
'	For i=0 To res.Size-1
'		Log("key:"&res.GetKeyAt(i)&" val:"&res.GetValueAt(i))
'	Next
	Dim uid As String=res.Get("userid")
	Dim pname As String=res.Get("pname")
	pname=pname.ToLowerCase
	doLoginByThird(uid,pname)
End Sub
Sub doLoginByThird(userid As String,pname As String)
	comm.showProgress("正在登录请稍后")
	gUid=userid
	gPname=pname
	ParseHelper.doPostReqArr(Me,"login",comm.getApi(comm.apiIdx.REQLOGINBYTHIRD),Array As String("userid",userid,"pname",pname),"")
End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub JobDone(thj As HttpJob)
	ProgressDialogHide
	If thj.Success Then
		'Dim resMap As Map=thj.resHeader
		'Log(resMap)
		'resMap.Get(
		Dim str As String=thj.GetString
		Log(str)
		Dim netres=ParseHelper.getStatusData(str) As netRes
		Select thj.JobName
		Case "login"
			If netres.nCode==200 Then
				'更新cookie
				ParseHelper.updateCookie(thj.GetHeader)
				Dim mi As myInfo=ParseHelper.parseMyInfo(str)
				If mi.jpush_pwd.Length<5 Then
					'极光账号没注册,调用注册
					Starter.jmsg.register(mi.usertel,comm.S_JPUSH_PASS)
				Else
					'登录
					Starter.jmsg.login(mi.usertel,mi.jpush_pwd)
				End If	
				g_store.conf.Put("islogin",True)
				CallSubDelayed(actmain,"fillmyinfo")
				Activity.Finish
			else if netres.nCode=102 Then
				comm.TL("本账户尚未绑定任何本平台账号，注册后自动绑定")
				StartActivity(actRegister)
			Else
				ToastMessageShow("登录失败:"&netres.sData,True)
			End If
		End Select
		
	Else
		comm.TL("发生错误:"&thj.JobName&CRLF&thj.ErrorMessage)
	End If
	thj.Release
End Sub

Sub doLogin(username As String,password As String)
	ParseHelper.doPostReqArr(Me,"login",comm.getApi(comm.apiIdx.LOGIN),Array As String("account",username,"password",password),"")
End Sub
Sub ivback_Click
	Activity.Finish
End Sub

Sub lblloginbysms_Click
	StartActivity(actLoginSms)
	Activity.Finish
End Sub

Sub btnlogin_Click
	If edtpasswd.Text.Trim.Length>0 And edtphone.Text.Trim.Length>0 Then
		ProgressDialogShow2("正在登录请稍后",False)
		doLogin(edtphone.Text.Trim,edtpasswd.Text.Trim)
	End If

End Sub

Sub lblforgotpass_Click
	StartActivity(actForgotPass)
End Sub

Sub lblregister_Click
	StartActivity(actRegister)
End Sub

Sub ivwxlogin_Click
	thirdlogin.LoginByWeixin
End Sub

Sub ivwblogin_Click
	thirdlogin.LogoutByQQZone
	thirdlogin.LogoutByWeixin
End Sub

Sub ivqqlogin_Click
	thirdlogin.LoginByQQZone
End Sub